#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
Python ACME Network Client
'''
from xmlrpc.client import ServerProxy
import argparse
import time

ACME_RPC_PORT = 6666
# ACME_RPC_HOSTNAME = "baylibre-acme.local"

parser = argparse.ArgumentParser()
parser.add_argument("-s", "--server", help="Specify ACME Hostname")
parser.add_argument("-d", "--device", help="Specify device name")
parser.add_argument("command", help="ACME Command, use 'help' to get all commands")
parser.add_argument("args", nargs='?', help="ACME Command Arguments")
args = parser.parse_args()
# print ('aaaaa',args)


serveraddr = "%s:%d" % (args.server, ACME_RPC_PORT)

s = ServerProxy("http://%s/" % serveraddr)



if args.command == "switch_on":
	if not args.args:
		print("Switch command parameters : <probe>")
	else:
		print(s.switch_on(args.device, args.args))
elif args.command == "switch_off":
	if not args.args:
		print("Switch command parameters : <probe>")
	else:
		print(s.switch_off(args.device, args.args))
elif args.command == "reset":
	if not args.args:
		print("Switch command parameters : <probe>")
	else:
		print(s.switch_off(args.device, args.args))
		time.sleep(4)
		print(s.switch_on(args.device, args.args))
else:
	print("Unknown command %s" % args.command)